-
Notifications
You must be signed in to change notification settings - Fork 15.4k
DAG: Add overload of makeLibCall which calls an RTLIB::LibcallImpl #170584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arsenm
wants to merge
1
commit into
main
Choose a base branch
from
users/arsenm/dag/add-makeLibCall-overload-libcall-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
DAG: Add overload of makeLibCall which calls an RTLIB::LibcallImpl #170584
arsenm
wants to merge
1
commit into
main
from
users/arsenm/dag/add-makeLibCall-overload-libcall-impl
+44
−26
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
This was referenced Dec 4, 2025
Member
|
@llvm/pr-subscribers-llvm-selectiondag Author: Matt Arsenault (arsenm) ChangesLogically the concrete implementation is what's being called, not Full diff: https://github.com/llvm/llvm-project/pull/170584.diff 4 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 149366c69bdcc..621cef5ef6230 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4116,12 +4116,21 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
}
/// Returns a pair of (return value, chain).
+ /// It is an error to pass RTLIB::Unsupported as \p LibcallImpl
+ std::pair<SDValue, SDValue>
+ makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl, EVT RetVT,
+ ArrayRef<SDValue> Ops, MakeLibCallOptions CallOptions,
+ const SDLoc &dl, SDValue Chain = SDValue()) const;
+
/// It is an error to pass RTLIB::UNKNOWN_LIBCALL as \p LC.
std::pair<SDValue, SDValue> makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC,
EVT RetVT, ArrayRef<SDValue> Ops,
MakeLibCallOptions CallOptions,
const SDLoc &dl,
- SDValue Chain = SDValue()) const;
+ SDValue Chain = SDValue()) const {
+ return makeLibCall(DAG, getLibcallImpl(LC), RetVT, Ops, CallOptions, dl,
+ Chain);
+ }
/// Check whether parameters to a call that are passed in callee saved
/// registers are the same as from the calling function. This needs to be
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index dbdd913fccdb2..545b7f5120d35 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -802,7 +802,8 @@ bool DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
assert(VT == N->getValueType(1) &&
"expected both return values to have the same type");
- if (TLI.getLibcallImpl(LC) == RTLIB::Unsupported)
+ RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
+ if (LCImpl == RTLIB::Unsupported)
return false;
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
@@ -831,8 +832,9 @@ bool DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
CallOptions.setTypeListBeforeSoften({OpsVT}, VT)
.setOpsTypeOverrides(CallOpsTypeOverrides);
- auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT, Ops, CallOptions, DL,
- /*Chain=*/SDValue());
+ auto [ReturnVal, Chain] =
+ TLI.makeLibCall(DAG, LCImpl, NVT, Ops, CallOptions, DL,
+ /*Chain=*/SDValue());
auto CreateStackLoad = [&, Chain = Chain](SDValue StackSlot) {
int FrameIdx = cast<FrameIndexSDNode>(StackSlot)->getIndex();
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 8c9f5eeebd26c..94a3386e75394 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -2692,7 +2692,8 @@ SDValue DAGTypeLegalizer::PromoteIntOp_ExpOp(SDNode *N) {
RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(N->getValueType(0))
: RTLIB::getLDEXP(N->getValueType(0));
- if (TLI.getLibcallImpl(LC) == RTLIB::Unsupported) {
+ RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
+ if (LCImpl == RTLIB::Unsupported) {
// Scalarize vector FPOWI instead of promoting the type. This allows the
// scalar FPOWIs to be visited and converted to libcalls before promoting
// the type.
@@ -2719,7 +2720,7 @@ SDValue DAGTypeLegalizer::PromoteIntOp_ExpOp(SDNode *N) {
CallOptions.setIsSigned(true);
SDValue Ops[2] = {N->getOperand(0 + OpOffset), N->getOperand(1 + OpOffset)};
std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
- DAG, LC, N->getValueType(0), Ops, CallOptions, SDLoc(N), Chain);
+ DAG, LCImpl, N->getValueType(0), Ops, CallOptions, SDLoc(N), Chain);
ReplaceValueWith(SDValue(N, 0), Tmp.first);
if (IsStrict)
ReplaceValueWith(SDValue(N, 1), Tmp.second);
@@ -3187,7 +3188,9 @@ std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(SDNode *Node) {
EVT RetVT = Node->getValueType(0);
TargetLowering::MakeLibCallOptions CallOptions;
SmallVector<SDValue, 4> Ops;
- if (TLI.getLibcallName(LC)) {
+
+ RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
+ if (LCImpl != RTLIB::Unsupported) {
Ops.append(Node->op_begin() + 2, Node->op_end());
Ops.push_back(Node->getOperand(1));
} else {
@@ -3195,8 +3198,9 @@ std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(SDNode *Node) {
assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected atomic op or value type!");
Ops.append(Node->op_begin() + 1, Node->op_end());
+ LCImpl = TLI.getLibcallImpl(LC);
}
- return TLI.makeLibCall(DAG, LC, RetVT, Ops, CallOptions, SDLoc(Node),
+ return TLI.makeLibCall(DAG, LCImpl, RetVT, Ops, CallOptions, SDLoc(Node),
Node->getOperand(0));
}
@@ -4403,8 +4407,8 @@ void DAGTypeLegalizer::ExpandIntRes_MUL(SDNode *N,
// If nothing else, we can make a libcall.
RTLIB::Libcall LC = RTLIB::getMUL(VT);
-
- if (LC == RTLIB::UNKNOWN_LIBCALL || !TLI.getLibcallName(LC)) {
+ RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
+ if (LCImpl == RTLIB::Unsupported) {
// Perform a wide multiplication where the wide type is the original VT and
// the 4 parts are the split arguments.
TLI.forceExpandMultiply(DAG, dl, /*Signed=*/false, Lo, Hi, LL, RL, LH, RH);
@@ -4416,8 +4420,8 @@ void DAGTypeLegalizer::ExpandIntRes_MUL(SDNode *N,
SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
TargetLowering::MakeLibCallOptions CallOptions;
CallOptions.setIsSigned(true);
- SplitInteger(TLI.makeLibCall(DAG, LC, VT, Ops, CallOptions, dl).first,
- Lo, Hi);
+ SplitInteger(TLI.makeLibCall(DAG, LCImpl, VT, Ops, CallOptions, dl).first, Lo,
+ Hi);
}
void DAGTypeLegalizer::ExpandIntRes_READCOUNTER(SDNode *N, SDValue &Lo,
@@ -4991,14 +4995,16 @@ void DAGTypeLegalizer::ExpandIntRes_Shift(SDNode *N,
LC = RTLIB::getSRA(VT);
}
- if (LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC)) {
+ if (RTLIB::LibcallImpl LibcallImpl = TLI.getLibcallImpl(LC)) {
EVT ShAmtTy =
EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
SDValue ShAmt = DAG.getZExtOrTrunc(N->getOperand(1), dl, ShAmtTy);
SDValue Ops[2] = {N->getOperand(0), ShAmt};
TargetLowering::MakeLibCallOptions CallOptions;
CallOptions.setIsSigned(isSigned);
- SplitInteger(TLI.makeLibCall(DAG, LC, VT, Ops, CallOptions, dl).first, Lo, Hi);
+ SplitInteger(
+ TLI.makeLibCall(DAG, LibcallImpl, VT, Ops, CallOptions, dl).first, Lo,
+ Hi);
return;
}
@@ -5158,11 +5164,12 @@ void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
// Replace this with a libcall that will check overflow.
RTLIB::Libcall LC = RTLIB::getMULO(VT);
+ RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
// If we don't have the libcall or if the function we are compiling is the
// implementation of the expected libcall (avoid inf-loop), expand inline.
- if (LC == RTLIB::UNKNOWN_LIBCALL || !TLI.getLibcallName(LC) ||
- TLI.getLibcallName(LC) == DAG.getMachineFunction().getName()) {
+ if (LCImpl == RTLIB::Unsupported ||
+ TLI.getLibcallImplName(LCImpl) == DAG.getMachineFunction().getName()) {
// FIXME: This is not an optimal expansion, but better than crashing.
SDValue MulLo, MulHi;
TLI.forceExpandWideMUL(DAG, dl, /*Signed=*/true, N->getOperand(0),
@@ -5200,12 +5207,14 @@ void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
Entry.IsZExt = false;
Args.push_back(Entry);
- SDValue Func = DAG.getExternalSymbol(TLI.getLibcallName(LC), PtrVT);
+ SDValue Func =
+ DAG.getExternalSymbol(TLI.getLibcallImplName(LCImpl).data(), PtrVT);
TargetLowering::CallLoweringInfo CLI(DAG);
CLI.setDebugLoc(dl)
.setChain(Chain)
- .setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Func, std::move(Args))
+ .setLibCallee(TLI.getLibcallImplCallingConv(LCImpl), RetTy, Func,
+ std::move(Args))
.setSExtResult();
std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 1e71937372159..87eb56dbed61b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -152,11 +152,13 @@ void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
/// Generate a libcall taking the given operands as arguments and returning a
/// result of type RetVT.
std::pair<SDValue, SDValue>
-TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
- ArrayRef<SDValue> Ops,
- MakeLibCallOptions CallOptions,
- const SDLoc &dl,
+TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl,
+ EVT RetVT, ArrayRef<SDValue> Ops,
+ MakeLibCallOptions CallOptions, const SDLoc &dl,
SDValue InChain) const {
+ if (LibcallImpl == RTLIB::Unsupported)
+ reportFatalInternalError("unsupported library call operation");
+
if (!InChain)
InChain = DAG.getEntryNode();
@@ -185,10 +187,6 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
Args.push_back(Entry);
}
- RTLIB::LibcallImpl LibcallImpl = getLibcallImpl(LC);
- if (LibcallImpl == RTLIB::Unsupported)
- reportFatalInternalError("unsupported library call operation");
-
SDValue Callee = DAG.getExternalSymbol(getLibcallImplName(LibcallImpl).data(),
getPointerTy(DAG.getDataLayout()));
|
Base automatically changed from
users/arsenm/dag/avoid-getLibcallName-checks
to
main
December 4, 2025 16:49
Logically the concrete implementation is what's being called, not the abstract libcall. Many uses conditionalize emitting the call on whether the call is available, so the caller and makeLibCall would both be checking that.
65dee89 to
3db09b7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Logically the concrete implementation is what's being called, not
the abstract libcall. Many uses conditionalize emitting the call on
whether the call is available, so the caller and makeLibCall would
both be checking that.